package com.yanqu.road.server.cmd.activity.tonbingchannel.channel;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChannelTonBingProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = GameProtocol.S_CHANNEL_CTON_BING_POS_REWARD_SYNC, desc = "")
public class TonBingCrossPosRewardSyncCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        ChannelTonBingProto.ChannelTonBingPositionSliverSyncMsg syncMsg = ChannelTonBingProto.ChannelTonBingPositionSliverSyncMsg.parseFrom(packet.getBytes());
        for(ChannelTonBingProto.ChannelTonBingPositionUserMsg userMsg : syncMsg.getUserList()){
            long userId = userMsg.getUserId();
            GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
            if(player != null){
                ChannelTonBingProto.CTonBingPosRewardSyncMsg.Builder syncUserMsg = ChannelTonBingProto.CTonBingPosRewardSyncMsg.newBuilder();
                syncUserMsg.addAllList(userMsg.getSliverUserList());
                player.sendPacket(ClientProtocol.U_CTON_BING_POS_REWARD_SYNC, syncUserMsg);
            }
        }
    }

}
